package dustlog;

import interfaz2.LogView;

/**
 * Following the MVC design pattern, this class is the module controller of
 * every log generated in Dust. At the start of Dust this module is initialized
 * and then every component/module of Dust can call the log() method to log
 * a message.
 * 
 * If you plan to give Dust more functionality you should use this module to
 * log information, and please, never ever call the LogView.addLog() method
 * directly.
 * 
 * @author ole
 */
public class LogController {
	// Class attributes.
	private static LogView view = null;
	
	/*
	 * Public methods of class LogController
	 */
	
	/**
	 * The interface between any method that wants to log something and the
	 * view that show those logs.
	 */
	public static void log(String msg) {
		if (view == null)
			System.err.println("[WARN]: Module LogController not initialized.");
		else
			view.addLog(msg);
	}
	
	/**
	 * Sets the view that will show the logs. Before use the log() method it is
	 * mandatory to invoke this method.
	 */
	public static void setView(LogView new_view) {
		view = new_view;
	}
}
